Quality control and filtering results from cellranger

Sample info and environment setup

PRJNA732205

setwd("/media/jacopo/Elements/re_align/MM/PRJNA732205/SAMN19314105/SRR14629339/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree 
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)

Load and process cellranger data

Load and do the QC for the cellranger data

#list.files(".")
dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial, 
    "\nNumber of genes:",  dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 3798 
## Number of genes: 36601

Quality Control

Empty cells were already filtered, check for % mt RNA and death markers:

# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 20
max_counts = 40000



# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt"))  + geom_hline(yintercept=mt_rna, linetype = "dotted")

plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1 

plot2

##  cells retained by mt RNA content ( 20 %): 3420 
##  percentage of retained cells: 90.05 %
## cells retained by counts ( 40000 ): 3224 
##  percentage of retained cells: 84.89 %

Check the distribution of the cells with low counts and control death markers:

min_counts = 200


hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")

hist(dat@meta.data$nCount_RNA, breaks = 1000, xlab = "Counts", xlim = c(0,5000))

hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)

The evident peak of cells with < 200 counts could contain dying cells.

# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)

# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)

# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)

# Print the most highly expressed genes
head(meanCounts, 30)
##      IGLC2      IGHA1     MALAT1        B2M     S100A8       MZB1      HLA-B 
## 54.8627451  7.8692810  5.3267974  4.5098039  1.3267974  0.7581699  0.6078431 
##       SSR4      NEAT1      RPLP1      DEFA3       IGKC     MT-CO3     S100A9 
##  0.5555556  0.5032680  0.4444444  0.4183007  0.3921569  0.3921569  0.3594771 
##      RPL41     JCHAIN        UBC      IGLC1        FTL      ITM2C    HSP90B1 
##  0.3333333  0.2941176  0.2810458  0.2745098  0.2549020  0.2483660  0.2418301 
##      IGLC3     MT-CO2      RPS18       PTMA     TMSB4X      RPL10    KRTCAP2 
##  0.2352941  0.2352941  0.2222222  0.2156863  0.2156863  0.2156863  0.2026144 
##     MT-CYB     TMSB10 
##  0.2026144  0.1960784
## cells retained by counts ( 200 ): 3071 
##  percentage of retained cells: 80.86 %

dir.create("result")
saveRDS(dat, file = "./result/SAMN19314105_clean_QC.Rds")

Feature selection

#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)

Data scaling

Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering

# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data

all.genes <- rownames(dat)

dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))

Dimensionality reduction

dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1 
## Positive:  HBA1, HBA2, HBB, ALAS2, IGHA1 
## Negative:  STMN1, BIRC5, H2AFZ, TK1, UBE2T 
## PC_ 2 
## Positive:  STMN1, NUSAP1, BIRC5, RRM2, PBK 
## Negative:  RPS14, RPS27, B2M, RPS18, RPL34 
## PC_ 3 
## Positive:  S100A4, LY86, CXCR4, ARHGDIB, CORO1A 
## Negative:  MZB1, Z93930.2, XBP1, FKBP11, NEAT1 
## PC_ 4 
## Positive:  Z93930.2, NEAT1, PPP1R10, CDK14, AC104024.1 
## Negative:  MYDGF, SEC11C, MANF, MZB1, PDIA4 
## PC_ 5 
## Positive:  IGHA2, IGHA1, MZB1, B2M, IGLC3 
## Negative:  HBB, HBA1, HBA2, HBD, BLVRB

UMAP

UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:

dat <- FindNeighbors(dat, dims = 1:20)

The graph now can be used as input for the function runUMAP()

dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)

Final plots:

## QC metrics

## markers